import ctypes
import sys
from PyQt5.QtCore import QFile
from PyQt5.QtWidgets import QApplication
import setting
from page.page_main import main
from page.page_update import FormUpdate
def load_qss(file_path):
    file = QFile(file_path)
    if not file.open(QFile.ReadOnly | QFile.Text):
        print("无法打开文件")
        return ""
    stylesheet = file.readAll().data().decode()
    return stylesheet
if __name__ == "__main__":
    if ctypes.windll.shell32.IsUserAnAdmin():
        app = QApplication(sys.argv)  # 初始化Qt应用
        # 加载皮肤
        qss = load_qss('datas/app.qss')
        app.setStyleSheet(qss)

        
        #主窗口
        window_main = main()
        window_main.show()
        window_main.update_ui(setting.p_left, setting.p_top)

        if window_main.auto_tft.moni.hwnd==0:
            window_main.update_ui()

        sys.exit(app.exec_())#监听消息不关闭
    else:
        # 如果不是管理员，则请求以管理员权限重新运行程序
        ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
